package com.aircms.controller.admin;

import ch.qos.logback.core.util.FileUtil;
import com.aircms.common.ServerResponse;
import com.aircms.controller.BaseAdminController;
import com.aircms.util.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author air
 * @create 2018-09-22 下午6:41
 */
@RestController
@RequestMapping(value = "api/admin/auth/upload")
public class UploadAdminController extends BaseAdminController {

    @Value("${web.upload-path}")
    private String path;

    /**
     * Store a newly created resource in storage.
     *
     * @return
     */
    @PostMapping(value = "uploadImage")
    public ServerResponse uploadImage(@RequestParam("file") MultipartFile file) throws Exception {
        try {
            FileUtils fileUtils=new FileUtils();
            if(fileUtils.upload(file,path)){
                return ServerResponse.response(fileUtils);
            }else {
                return ServerResponse.response("",-111);
            }
        } catch (Exception e) {
            throw new Exception(e);
        }
    }






}
